package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {
        /*
        从文件中读取文本数据
        1.创建一个文件输入流
        2.从文件中将字节读取回来
        3.字节转字符串
         */
        FileInputStream fis = new FileInputStream("fos.txt");
        byte[] data = new byte[1024];
        int len = fis.read(data);
        System.out.println("实际读取到了" + len + "个字节");
        String line = new String(data,0,len,StandardCharsets.UTF_8);//字节转字符
        System.out.println(line);
        //UTF-8中一个字占3个字节
    }
}
